#!/usr/bin/env bash

if [ -z "$WM_PROJECT" ]; then
  echo "OpenFOAM environment not found, forgot to source the OpenFOAM bashrc?"
  exit 1
fi

case $1 in
  "opt")
    for d in ./*/ ; do 
      cd "$d" 
      python setup.py build_ext --inplace || exit 1
      mv *.so ../../../../dafoam
      cd ../
    done
    ;;
  "debug")
    for d in ./*/ ; do 
      cd "$d" 
      python setup.py build_ext --inplace || exit 1
      mv *.so ../../../../dafoam
      cd ../
    done
    ;;
  "incompressible")
    cd pyColoringIncompressible && python setup.py build_ext --inplace || exit 1
    mv *.so ../../../../dafoam
    ;;
  "compressible")
    cd pyColoringCompressible && python setup.py build_ext --inplace || exit 1
    mv *.so ../../../../dafoam
    ;;
  "solid")
    cd pyColoringSolid && python setup.py build_ext --inplace || exit 1
    mv *.so ../../../../dafoam
    ;;
  *)
    echo "Argument not valid! Options are: opt, debug, incompressible, compressible, or solid"
    echo "Example: ./Allmake opt"
    exit 1
    ;;
esac